//
//  UIView+Mask.m
//  ThunderChat
//
//  Created by Kelly xu on 2018/10/18.
//  Copyright © 2018年 Simubang. All rights reserved.
//

#import "UIView+Mask.h"

@implementation UIView (Mask)
-(void)addCurveCornerWithSize:(CGSize)size{
    CGFloat halfWidth = size.width/2.0;
    CGFloat width = size.width;
    CGFloat minControlPoint = size.width*0.13423;
    CGFloat maxControPoint = size.width*0.86577;
    UIBezierPath *path =  [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(0.0, halfWidth)];
    [path addCurveToPoint:CGPointMake(halfWidth, 0.0) controlPoint1:CGPointMake(0.0, minControlPoint) controlPoint2:CGPointMake(minControlPoint, 0.0)];
    [path addCurveToPoint:CGPointMake(width, halfWidth) controlPoint1:CGPointMake(maxControPoint, 0.0) controlPoint2:CGPointMake(width, minControlPoint)];
    [path addCurveToPoint:CGPointMake(halfWidth, width) controlPoint1:CGPointMake(width, maxControPoint) controlPoint2:CGPointMake(maxControPoint, width)];
    [path addCurveToPoint:CGPointMake(0.0, halfWidth) controlPoint1:CGPointMake(minControlPoint, width) controlPoint2:CGPointMake(0.0, maxControPoint)];
    //    [path addClip];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
    //设置大小
    maskLayer.frame = self.bounds;
    //设置图形样子
    maskLayer.path = path.CGPath;
    self.layer.mask = maskLayer;
}
-(void)addQueCurveCornerWithSize:(CGSize)size{
    CGFloat modeWidth = size.width/20;
    UIBezierPath *path =  [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(modeWidth*10, modeWidth*0)];
    [path addCurveToPoint:CGPointMake(modeWidth*20, modeWidth*10) controlPoint1:CGPointMake(modeWidth*17.315,modeWidth* 0) controlPoint2:CGPointMake(modeWidth*20, modeWidth*2.724)];
    [path addCurveToPoint:CGPointMake(modeWidth*10, modeWidth*20) controlPoint1:CGPointMake(modeWidth*20, modeWidth*17.276) controlPoint2:CGPointMake(modeWidth*17.315, modeWidth*20)];
    [path addCurveToPoint:CGPointMake(modeWidth*1, modeWidth*15.892) controlPoint1:CGPointMake(modeWidth*5.15,modeWidth* 20) controlPoint2:CGPointMake(modeWidth*2.351, modeWidth*18.811)];
    [path addCurveToPoint:CGPointMake(modeWidth*2, modeWidth*10) controlPoint1:CGPointMake(modeWidth*1.692, modeWidth*14.402) controlPoint2:CGPointMake(modeWidth*2, modeWidth*12.483)];
    [path addCurveToPoint:CGPointMake(modeWidth*1,modeWidth*4.118) controlPoint1:CGPointMake(modeWidth*2, modeWidth*7.53) controlPoint2:CGPointMake(modeWidth*1.672, modeWidth*5.607)];
    [path addCurveToPoint:CGPointMake(modeWidth*10, modeWidth*0) controlPoint1:CGPointMake(modeWidth*2.345, modeWidth*1.919) controlPoint2:CGPointMake(modeWidth*5.15, modeWidth*0)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
    //设置大小
    maskLayer.frame = self.bounds;
    //设置图形样子
    maskLayer.path = path.CGPath;
    self.layer.mask = maskLayer;
}
@end
